<template>
  <div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
        </span>

      </a-table>
    </div>
    <pp-work-order-report-modal ref="modalForm" @ok="modalFormOk"></pp-work-order-report-modal>
  </div>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import PpWorkOrderReportModal from './modules/PpWorkOrderReportModal'
  import {getAction} from "@/api/manage";

  export default {
    name: 'PpWorkOrderReportTable',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      PpWorkOrderReportModal
    },
    props:{
      initQueryParam:{},
      initAddModel:{}
    },
    data () {
      return {
        description: '生产工单汇报单管理页面',
        // 表头
        columns: [
          {
            title:'汇报单号',
            align:"center",
            dataIndex: 'reportNo'
          },
          {
            title:'工序编号',
            align:"center",
            dataIndex: 'processNo'
          },
          {
            title:'工序名称',
            align:"center",
            dataIndex: 'processName'
          },

          {
            title:'汇报数量',
            align:"center",
            dataIndex: 'reportQty'
          },
          {
            title:'工作中心',
            align:"center",
            dataIndex: 'workId'
          },
          {
            title:'汇报人',
            align:"center",
            dataIndex: 'reportUser'
          },
          {
            title:'汇报日期',
            align:"center",
            dataIndex: 'reportDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'合格数量',
            align:"center",
            dataIndex: 'checkQty'
          },
          {
            title:'废品数量',
            align:"center",
            dataIndex: 'scrapQty'
          },
          {
            title:'返修数量',
            align:"center",
            dataIndex: 'reworkQty'
          },
          {
            title:'面积',
            align:"center",
            dataIndex: 'areaNum'
          },
          {
            title:'重量',
            align:"center",
            dataIndex: 'weight'
          },
          {
            title:'工时',
            align:"center",
            dataIndex: 'reportTime'
          },
          {
            title:'检验人',
            align:"center",
            dataIndex: 'checkUser'
          },
          {
            title:'检验日期',
            align:"center",
            dataIndex: 'checkDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'接收人',
            align:"center",
            dataIndex: 'receiveUser'
          },
          {
            title:'接收日期',
            align:"center",
            dataIndex: 'receiveDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'接收工作中心',
            align:"center",
            dataIndex: 'receiveWorkId'
          },
          {
            title:'检验部门',
            align:"center",
            dataIndex: 'checkDept'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:100,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/pp/workOrderReport/list",
          delete: "/pp/workOrderReport/delete",
          deleteBatch: "/pp/workOrderReport/deleteBatch",
          exportXlsUrl: "/pp/workOrderReport/exportXls",
          importExcelUrl: "pp/workOrderReport/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        Object.assign(this.queryParam, this.initQueryParam);
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
    }
  }
</script>
<style scoped>
.ant-card-body .table-operator {
  margin-bottom: 0px;
}
</style>